﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Protoss
{
	public class ActionProduceMothership : ActionProduceProtoss
	{
		public static ActionProduceMothership Instance = new ActionProduceMothership();

		private ActionProduceMothership() : base(160, 400, 400, 8) { }

		public override int AvailableProducer(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			return state.Nexus.AvailableForProduction;
		}

		public override bool IsInvalid(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			return base.IsInvalid(bo) || state.FleetBeacon.Total == 0;
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			return state.FleetBeacon.Count > 0;
		}

		public void OnProductionFinished(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			state.Mothership++;
		}

		private IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceFleetBeacon.Instance } };
				return m_Requirements;
			}
		}

		public override void Execute(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			base.Execute(bo);
			state.Nexus.Production++;
			bo.AddAction(state.Time + BuildTime, new ActionGeneric("ActionSpawnMothership", (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				ProtossState ibostate = ibo.State as ProtossState;
				ibostate.Nexus.Production--;
				OnProductionFinished(ibo);
			}));

		}
	}
}
